﻿using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.OfficeArt
{
    internal class  OfficeArtBlipJPEG : OfficeArtStandardBlip
    {
        public OfficeArtBlipJPEG(byte[] data, JpegFormat format)
            : base(data)
        {
            Contract.Requires(Enum.IsDefined(typeof(JpegFormat), format));
            Contract.Assert(GetDigest() != null);
            NativeFormat = format;
        }

        public OfficeArtBlipJPEG()
        {
        
        }


        public override RecType RecordType
        {
            get { return RecType.OfficeArtBlipJPEG; }
        }


        public enum JpegFormat: ushort
        {
            RGB1 = 0x46A,
            RGB2 = 0x46B,
            CMYK1 = 0x6E2,
            CMYK2 = 0x6E3,
        }


        protected override string Extension
        {
            get { return "jpeg"; }
        }

        protected override ushort Format
        {
            get { return (ushort) NativeFormat;   }
            set { NativeFormat = (JpegFormat) value; }
        }
        private JpegFormat _nativeFormat;

        public JpegFormat NativeFormat
        {
            get
            {
                Contract.Ensures(Enum.IsDefined(typeof(JpegFormat), Contract.Result<JpegFormat>()));
                return _nativeFormat;
            }
            set
            {
                Contract.Requires(Enum.IsDefined(typeof (JpegFormat), value));
                _nativeFormat = value;
            }
        }
        
        protected override UidCount HasTwoIds()
        {
            JpegFormat type = (JpegFormat)NativeFormat;
            switch (type)
            {
                case JpegFormat.CMYK2:
                case JpegFormat.RGB2:
                    return UidCount.Two;
                    break;
                case JpegFormat.CMYK1:
                case JpegFormat.RGB1:
                    return UidCount.One;
                default: throw new NotSupportedException();
            }
        }

        internal override MSOBLIPTYPE Type
        {
            get { return MSOBLIPTYPE.msoblipJPEG; }
        }
    }
}